In [1]:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
import datetime
import matplotlib.dates as mdates


%matplotlib inline

In [2]:
df = pd.read_csv('~/development/vinepair_time_series.csv')
pub_dates = pd.read_csv('~/development/slugs_dates_vinepair_posts.csv',parse_dates=True)

In [3]:
df.head(1)


Out[3]:
Unnamed: 0 10-affordable-chardonnays-that-arent-oak-bombs 10-ancient-archaeological-wine-discoveries 10-best-beers-mikkellers-copenhagen-beer-music-celebration 10-best-labor-day-cocktails 10-best-red-wines-for-tailgating 10-boozy-holiday-desserts 10-bottles-of-torrontes-to-add-to-your-summer-drinking-list 10-charming-drink-accessories-to-make-your-christmas-shine-brighter 10-elegant-and-efficient-countertop-storage-solutions-for-your-wine ... your-new-favorite-backyard-wine-accessory-the-porron your-new-favorite-region-for-pinots-is-in-germany your-official-guide-to-the-wines-of-the-star-wars-universe your-port-glass-is-tiny-for-a-reason youre-making-the-sazerac-incorrectly youre-probably-drinking-illegal-dark-n-stormys-youre-also-probably-making-the-drink-wrong youre-probably-drinking-storing-and-making-cocktails-with-your-vermouth-wrong youre-serving-your-white-wine-too-cold yuengling-being-named-a-craft-brewer-signals-crafts-intention-to-spend-big-bucks-agains-big-beer zinfandel-the-all-american-grape-comes-from-kastela-croatia
0 0 457.0 36.0 1235.0 398.0 431.0 236.0 592.0 2.0 83.0 ... 658.0 459.0 1.0 266.0 1.0 1122.0 1.0 816.0 1.0 224.0

1 rows × 2258 columns


In [4]:
pub_dates.head(1)


Out[4]:
Url Date
0 wine-wednesday 2013-08-07

In [5]:
pub_dates.dtypes


Out[5]:
Url     object
Date    object
dtype: object

In [6]:
pub_dates.Date.dtype
pub_dates.columns = ["Url","Published"]

In [7]:
pub_dates.Published = pd.to_datetime(pub_dates.Published)

In [8]:
pub_dates.Published.dtype


Out[8]:
dtype('<M8[ns]')

In [9]:
pub_dates.head(1)


Out[9]:
Url Published
0 wine-wednesday 2013-08-07

In [10]:
df = df.drop('Unnamed: 0',axis=1)
df = df.T
df.head(2)


Out[10]:
0 1 2 3 4 5 6 7 8 9 ... 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166
10-affordable-chardonnays-that-arent-oak-bombs 457.0 720.0 241.0 79.0 38.0 30.0 41.0 34.0 87.0 31.0 ... NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
10-ancient-archaeological-wine-discoveries 36.0 330.0 74.0 66.0 8.0 8.0 14.0 10.0 10.0 6.0 ... NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN

2 rows × 1167 columns


In [11]:
df = df.drop(df.columns[367:1168],axis='columns')

In [15]:
df['days_to_90p'] = [(df.iloc[x].expanding().sum() > df.iloc[x].sum()*.90).argmax()\
                     for x in range(len(df))]

In [16]:
df['total'] = df.sum(axis=1)

In [17]:
pub_dates = pub_dates.set_index('Url')
df = df.join(pub_dates)
df = df.reset_index()

In [18]:
df.iloc[0]


Out[18]:
index          10-affordable-chardonnays-that-arent-oak-bombs
0                                                         457
1                                                         720
2                                                         241
3                                                          79
4                                                          38
5                                                          30
6                                                          41
7                                                          34
8                                                          87
9                                                          31
10                                                         11
11                                                          8
12                                                          7
13                                                          5
14                                                         42
15                                                         21
16                                                          5
17                                                          5
18                                                          5
19                                                          6
20                                                          3
21                                                         35
22                                                         12
23                                                          3
24                                                          3
25                                                         10
26                                                          7
27                                                          2
28                                                          7
                                    ...                      
340                                                        66
341                                                        40
342                                                        42
343                                                        44
344                                                        42
345                                                        60
346                                                        60
347                                                        55
348                                                        44
349                                                        40
350                                                        45
351                                                        52
352                                                        45
353                                                        82
354                                                        46
355                                                        49
356                                                        46
357                                                        50
358                                                        62
359                                                        36
360                                                        54
361                                                        57
362                                                        62
363                                                        36
364                                                        43
365                                                        59
366                                                         0
days_to_90p                                               349
total                                                    8809
Published                                 2015-11-03 00:00:00
Name: 0, dtype: object

In [19]:
df.total.describe()


Out[19]:
count      2257.000000
mean       2628.321666
std       11638.794596
min           0.000000
25%           5.000000
50%         831.000000
75%        2307.000000
max      365701.000000
Name: total, dtype: float64

In [22]:
df = df[df.total > 200]

In [23]:
df.total.describe()


Out[23]:
count      1421.000000
mean       4166.553132
std       14450.569883
min         202.000000
25%         949.000000
50%        1763.000000
75%        3724.000000
max      365701.000000
Name: total, dtype: float64

In [24]:
df.days_to_90p.describe()


Out[24]:
count    1421.000000
mean      167.674173
std       127.005856
min         1.000000
25%        33.000000
50%       161.000000
75%       295.000000
max       365.000000
Name: days_to_90p, dtype: float64

In [25]:
ax = df.plot(x=df.index, y='days_to_90p',kind='density')
ax.set(xlabel='Days Since Publication',title = 'Density Distribution of Days until 90% of Traffic Achieved')


Out[25]:
[<matplotlib.text.Text at 0x11b1265d0>, <matplotlib.text.Text at 0x11b1572d0>]

In [26]:
df['month_published'] = pd.DatetimeIndex(df.Published).month
df['year_published'] = pd.DatetimeIndex(df.Published).year
df['month_year_published'] = df.month_published.astype(str) + "-" + df.year_published.astype(str)

In [27]:
sns.boxplot(y='days_to_90p',x='month_year_published',data=df.sort_values('month_year_published',ascending=True))


Out[27]:
<matplotlib.axes._subplots.AxesSubplot at 0x11b1dbc90>

In [28]:
df.month_published.head(1)


Out[28]:
0    11
Name: month_published, dtype: int32

In [29]:
len(df)


Out[29]:
1421

In [30]:
len(df.columns)


Out[30]:
374

In [31]:
df.plot(x=df.index,y='total',kind='density')


Out[31]:
<matplotlib.axes._subplots.AxesSubplot at 0x11b1db410>

In [32]:
df[df.days_to_90p > 150]


Out[32]:
index 0 1 2 3 4 5 6 7 8 ... 363 364 365 366 days_to_90p total Published month_published year_published month_year_published
0 10-affordable-chardonnays-that-arent-oak-bombs 457.0 720.0 241.0 79.0 38.0 30.0 41.0 34.0 87.0 ... 36.0 43.0 59.0 0.0 349 8809.0 2015-11-03 11 2015 11-2015
1 10-ancient-archaeological-wine-discoveries 36.0 330.0 74.0 66.0 8.0 8.0 14.0 10.0 10.0 ... 3.0 3.0 0.0 0.0 324 2168.0 2014-08-17 8 2014 8-2014
5 10-boozy-holiday-desserts 236.0 119.0 57.0 49.0 135.0 42.0 21.0 23.0 14.0 ... NaN NaN NaN NaN 311 1730.0 2015-12-14 12 2015 12-2015
14 10-great-gifts-for-beer-lovers 308.0 324.0 104.0 36.0 26.0 21.0 12.0 16.0 12.0 ... NaN NaN NaN NaN 254 1513.0 2015-12-22 12 2015 12-2015
21 10-intoxicating-honeymoon-drinks-to-relive-tha... 55.0 55.0 35.0 11.0 5.0 6.0 5.0 2.0 1.0 ... 3.0 3.0 4.0 NaN 324 1047.0 2015-08-26 8 2015 8-2015
26 10-red-hot-chili-beers-for-early-fall 117.0 43.0 7.0 2.0 3.0 164.0 145.0 34.0 19.0 ... 2.0 3.0 3.0 NaN 324 1439.0 2015-09-15 9 2015 9-2015
28 10-shades-of-rose-wine 211.0 619.0 176.0 103.0 70.0 87.0 55.0 69.0 82.0 ... 18.0 11.0 11.0 0.0 334 3867.0 2015-05-21 5 2015 5-2015
34 10-wine-accessories-christmas-dinner 36.0 11.0 14.0 5.0 17.0 5.0 6.0 1.0 1.0 ... 2.0 NaN NaN NaN 322 505.0 2013-12-16 12 2013 12-2013
36 10-worlds-weirdest-wine-labels 242.0 27.0 63.0 67.0 37.0 11.0 41.0 8.0 3.0 ... 27.0 10.0 11.0 0.0 321 6779.0 2014-05-09 5 2014 5-2014
37 100-point-wine-will-blend 120.0 21.0 21.0 22.0 9.0 6.0 10.0 0.0 3.0 ... 12.0 4.0 11.0 NaN 317 1223.0 2014-01-09 1 2014 1-2014
43 11-coolest-wine-themed-tattoos 1202.0 626.0 187.0 268.0 336.0 138.0 143.0 87.0 126.0 ... 6.0 7.0 5.0 0.0 328 9266.0 2014-10-23 10 2014 10-2014
44 11-craft-beer-labels-that-are-going-straight-t... 1429.0 2745.0 792.0 308.0 190.0 131.0 67.0 46.0 95.0 ... NaN NaN NaN NaN 231 9730.0 2016-02-25 2 2016 2-2016
46 11-exceptional-tequilas-under-50 365.0 486.0 278.0 70.0 31.0 29.0 16.0 23.0 34.0 ... 231.0 250.0 392.0 0.0 348 42128.0 2015-05-05 5 2015 5-2015
47 11-great-non-pumpkin-fall-beers 155.0 425.0 167.0 38.0 31.0 12.0 37.0 25.0 8.0 ... 13.0 11.0 11.0 0.0 338 5536.0 2015-10-27 10 2015 10-2015
53 11-things-you-didnt-know-about-gin 1059.0 526.0 1653.0 420.0 195.0 133.0 131.0 89.0 66.0 ... NaN NaN NaN NaN 249 7694.0 2016-02-03 2 2016 2-2016
58 11-weird-odors-found-in-sauvignon-blanc 440.0 107.0 56.0 37.0 12.0 18.0 7.0 10.0 3.0 ... 2.0 NaN NaN NaN 268 1677.0 2015-04-24 4 2015 4-2015
60 11-worlds-extreme-vineyards 102.0 484.0 273.0 245.0 1069.0 357.0 80.0 126.0 394.0 ... 5.0 3.0 8.0 0.0 180 6622.0 2014-06-15 6 2014 6-2014
62 12-best-bourbons-under-50-dollars 1739.0 1899.0 2881.0 884.0 442.0 190.0 132.0 93.0 108.0 ... 316.0 354.0 391.0 0.0 333 124898.0 2015-09-22 9 2015 9-2015
64 12-best-wine-junk-food-pairings 240.0 201.0 365.0 120.0 52.0 24.0 22.0 39.0 28.0 ... NaN NaN NaN NaN 268 3937.0 2016-01-11 1 2016 1-2016
66 12-celebrity-made-wines-for-christmas 99.0 133.0 26.0 12.0 11.0 7.0 12.0 4.0 3.0 ... 0.0 2.0 2.0 NaN 229 672.0 2013-12-03 12 2013 12-2013
71 12-incredible-instagram-photos-fall-wine-harvest 518.0 361.0 150.0 64.0 36.0 32.0 54.0 23.0 33.0 ... 2.0 1.0 1.0 0.0 335 3152.0 2014-10-07 10 2014 10-2014
78 12-uncomfortably-honest-growlers 119.0 102.0 63.0 17.0 21.0 4.0 174.0 28.0 21.0 ... NaN NaN NaN NaN 212 967.0 2016-02-25 2 2016 2-2016
79 12-vinepair-approved-christmas-music-wine-pair... 108.0 105.0 214.0 61.0 22.0 20.0 9.0 11.0 6.0 ... NaN NaN NaN NaN 212 908.0 2015-12-14 12 2015 12-2015
85 13-places-italy-every-wine-lover-bucket-list 2497.0 2228.0 923.0 1282.0 580.0 261.0 181.0 150.0 134.0 ... 18.0 17.0 27.0 0.0 153 25606.0 2015-04-05 4 2015 4-2015
87 13-sexist-beer-ads-since-1950s 465.0 375.0 470.0 217.0 230.0 106.0 40.0 43.0 42.0 ... 3.0 1.0 0.0 0.0 178 15900.0 2015-05-11 5 2015 5-2015
88 13-splurge-worthy-beers 1132.0 288.0 644.0 438.0 163.0 78.0 114.0 118.0 46.0 ... NaN NaN NaN NaN 253 5766.0 2015-12-04 12 2015 12-2015
98 14-flavored-stouts-to-ease-you-out-of-fall 325.0 118.0 256.0 161.0 36.0 16.0 2.0 8.0 6.0 ... NaN NaN NaN NaN 212 1448.0 2015-11-20 11 2015 11-2015
99 14-magical-winter-vineyards 491.0 83.0 144.0 86.0 34.0 22.0 71.0 142.0 36.0 ... 2.0 4.0 1.0 0.0 202 5399.0 2014-12-29 12 2014 12-2014
101 14-reasons-to-put-wine-in-your-shopping-cart-e... 401.0 295.0 166.0 73.0 204.0 165.0 66.0 30.0 23.0 ... 2.0 3.0 2.0 0.0 164 4706.0 2015-06-17 6 2015 6-2015
102 14-shandies-to-keep-your-thirst-quenched-all-s... 205.0 244.0 170.0 48.0 99.0 70.0 38.0 37.0 7.0 ... 19.0 8.0 15.0 0.0 356 8439.0 2015-06-09 6 2015 6-2015
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
2160 wine-etiquette-dining-clients 36.0 9.0 3.0 10.0 5.0 1.0 2.0 2.0 1.0 ... 3.0 1.0 2.0 NaN 361 829.0 2014-03-13 3 2014 3-2014
2166 wine-gift-tag-guide 56.0 11.0 15.0 12.0 4.0 11.0 3.0 0.0 0.0 ... 0.0 1.0 NaN NaN 186 351.0 2014-06-06 6 2014 6-2014
2171 wine-hack-find-wine-importer-trust 95.0 29.0 22.0 15.0 11.0 20.0 5.0 104.0 21.0 ... 0.0 0.0 0.0 0.0 169 698.0 2014-08-28 8 2014 8-2014
2172 wine-headache-cures 510.0 89.0 22.0 17.0 16.0 55.0 28.0 14.0 25.0 ... 30.0 24.0 13.0 0.0 324 18192.0 2014-05-13 5 2014 5-2014
2173 wine-health-roundup 14.0 6.0 1.0 4.0 2.0 0.0 0.0 3.0 0.0 ... NaN NaN NaN NaN 304 369.0 2014-01-05 1 2014 1-2014
2174 wine-help-survive-winter 22.0 4.0 2.0 4.0 1.0 5.0 0.0 0.0 0.0 ... NaN NaN NaN NaN 316 527.0 2014-01-10 1 2014 1-2014
2175 wine-in-a-can 11.0 3.0 2.0 2.0 3.0 0.0 1.0 0.0 0.0 ... NaN NaN NaN NaN 257 321.0 2014-01-09 1 2014 1-2014
2177 wine-influence-creativity-cartoon-exploration 44.0 64.0 20.0 9.0 0.0 2.0 1.0 0.0 3.0 ... NaN NaN NaN NaN 160 454.0 2014-05-18 5 2014 5-2014
2178 wine-inspired-new-years-eve-party-accessories 20.0 2.0 5.0 20.0 9.0 1.0 9.0 2.0 1.0 ... NaN NaN NaN NaN 319 467.0 2013-12-23 12 2013 12-2013
2181 wine-memories-roman-holiday 59.0 25.0 14.0 7.0 25.0 7.0 3.0 1.0 4.0 ... NaN NaN NaN NaN 153 361.0 2015-04-23 4 2015 4-2015
2183 wine-motivational-posters 821.0 2779.0 1090.0 783.0 249.0 123.0 112.0 77.0 147.0 ... 2.0 0.0 3.0 0.0 274 10458.0 2015-07-07 7 2015 7-2015
2184 wine-not-meant-aged 1032.0 743.0 255.0 118.0 97.0 61.0 44.0 30.0 33.0 ... 6.0 2.0 5.0 0.0 283 6377.0 2015-01-11 1 2015 1-2015
2194 wine-phrases-mean-plain-english 538.0 478.0 449.0 146.0 68.0 46.0 36.0 772.0 348.0 ... 3.0 3.0 6.0 0.0 275 12775.0 2015-01-05 1 2015 1-2015
2197 wine-school-lesson-four-overthinking-riesling-... 94.0 52.0 13.0 6.0 5.0 11.0 11.0 16.0 27.0 ... 1.0 NaN NaN NaN 257 703.0 2014-07-01 7 2014 7-2014
2199 wine-serve-bridal-shower 30.0 6.0 5.0 3.0 11.0 16.0 3.0 4.0 4.0 ... 7.0 6.0 6.0 0.0 349 1175.0 2014-04-16 4 2014 4-2014
2203 wine-storage-wine-on-the-go-pinterest 53.0 17.0 22.0 8.0 5.0 4.0 0.0 2.0 3.0 ... NaN NaN NaN NaN 151 355.0 2014-04-04 4 2014 4-2014
2205 wine-taught-me-to-relax-italy 29.0 8.0 7.0 2.0 11.0 7.0 2.0 7.0 2.0 ... 1.0 0.0 0.0 0.0 178 321.0 2014-02-18 2 2014 2-2014
2208 wine-wedding-party-ideas-pinterest 25.0 11.0 4.0 8.0 7.0 5.0 4.0 2.0 3.0 ... 1.0 1.0 NaN NaN 320 549.0 2014-05-12 5 2014 5-2014
2213 wines-favorite-cookie-oreo-booze-pairings 205.0 85.0 207.0 220.0 56.0 37.0 14.0 15.0 9.0 ... 3.0 3.0 9.0 0.0 310 2847.0 2015-06-19 6 2015 6-2015
2214 wines-ordered-drunk-now-pays 58.0 4.0 4.0 12.0 7.0 2.0 3.0 5.0 4.0 ... 3.0 NaN NaN NaN 206 553.0 2014-03-27 3 2014 3-2014
2218 winter-pairings-cassoulet-and-the-full-bodied-... 282.0 138.0 37.0 27.0 242.0 107.0 31.0 47.0 10.0 ... NaN NaN NaN NaN 292 36586.0 2016-01-06 1 2016 1-2016
2220 words-for-drunk-and-hungover 173.0 56.0 47.0 151.0 117.0 31.0 22.0 11.0 4.0 ... 0.0 3.0 0.0 0.0 292 1266.0 2015-01-29 1 2015 1-2015
2224 worlds-oldest-largest-cork-tree-the-whistler-tree 28.0 17.0 3.0 18.0 11.0 2.0 2.0 2.0 2.0 ... 9.0 12.0 2.0 NaN 345 2042.0 2014-04-03 4 2014 4-2014
2229 yes-animals-like-to-get-drunk-who-wouldnt 46.0 24.0 124.0 30.0 7.0 7.0 8.0 8.0 6.0 ... NaN NaN NaN NaN 172 523.0 2015-04-22 4 2015 4-2015
2230 yes-can-drink-champagne-regular-wine-glass 253.0 286.0 105.0 45.0 20.0 33.0 9.0 6.0 21.0 ... 7.0 3.0 3.0 0.0 291 2987.0 2014-11-04 11 2014 11-2014
2232 yes-theres-an-irish-whiskey-boom-but-not-becau... 1994.0 1234.0 827.0 271.0 87.0 53.0 29.0 17.0 8.0 ... 6.0 6.0 30.0 0.0 282 7844.0 2015-06-05 6 2015 6-2015
2233 you-always-remember-your-first-bourbon 157.0 81.0 281.0 109.0 49.0 34.0 18.0 13.0 22.0 ... 2.0 NaN NaN NaN 173 1271.0 2015-10-05 10 2015 10-2015
2234 you-broke-the-seal-already-ethan 425.0 1075.0 596.0 63.0 22.0 13.0 21.0 9.0 5.0 ... NaN NaN NaN NaN 187 3345.0 2016-03-08 3 2016 3-2016
2237 you-may-not-be-drinking-the-famous-stags-leap-... 1041.0 813.0 203.0 53.0 649.0 167.0 69.0 61.0 16.0 ... NaN NaN NaN NaN 251 6768.0 2016-02-22 2 2016 2-2016
2256 zinfandel-the-all-american-grape-comes-from-ka... 224.0 149.0 199.0 165.0 41.0 28.0 34.0 20.0 6.0 ... 0.0 0.0 0.0 0.0 304 2131.0 2015-03-27 3 2015 3-2015

738 rows × 374 columns


In [33]:
#I want a distribution of days-post-publication and PVs for the two modes.

In [34]:
fast = df[df.days_to_90p < 50]
slow = df[df.days_to_90p > 50]

In [35]:
fast[['days_to_90p','total']].describe()


Out[35]:
days_to_90p total
count 418.000000 418.000000
mean 17.059809 5223.653110
std 13.081694 23672.975861
min 1.000000 203.000000
25% 6.000000 1163.000000
50% 13.000000 1966.000000
75% 26.000000 3869.500000
max 49.000000 365701.000000

In [36]:
slow[['days_to_90p','total']].describe()


Out[36]:
days_to_90p total
count 998.000000 998.000000
mean 231.346693 3699.647295
std 96.250749 7835.074080
min 52.000000 202.000000
25% 148.000000 854.250000
50% 250.000000 1667.500000
75% 319.750000 3649.500000
max 365.000000 124898.000000

In [37]:
fast.T.mean(axis=0)


Out[37]:
Series([], dtype: float64)

In [38]:
ax = fast.drop(['total','days_to_90p','Published','month_published','year_published',
          "month_year_published"],axis=1).mean(axis=0).plot()
ax.set(xlabel='Days Since Publication',ylabel ='Average Daily Page Views',title = 'Average Daily Traffic for Content with short halflife')


Out[38]:
[<matplotlib.text.Text at 0x124863090>,
 <matplotlib.text.Text at 0x11c608710>,
 <matplotlib.text.Text at 0x124838d90>]

In [39]:
ax = slow.drop(['total','days_to_90p','Published','month_published','year_published',
          "month_year_published"],axis=1).mean(axis=0).plot()
ax.set(xlabel='Days Since Publication',ylabel ='Average Daily Page Views',title = 'Average Daily Traffic for Content with long halflife')


Out[39]:
[<matplotlib.text.Text at 0x124c962d0>,
 <matplotlib.text.Text at 0x124744950>,
 <matplotlib.text.Text at 0x124cc8210>]

In [40]:
slow.year_published.value_counts()


Out[40]:
2015    418
2016    275
2014    257
2013     48
Name: year_published, dtype: int64

In [41]:
fast.year_published.value_counts()


Out[41]:
2016    350
2015     51
2014     15
2013      2
Name: year_published, dtype: int64

Let's look at average traffic graphs for items published in 2015


In [42]:
ax = slow[slow.year_published == 2015].drop(['total','days_to_90p','Published','month_published','year_published',
          "month_year_published"],axis=1).mean(axis=0).plot()
ax.set(xlabel='Days Since Publication',ylabel ='Average Daily Page Views',title = 'Average Daily Traffic for Content with long halflife 2015 ')


Out[42]:
[<matplotlib.text.Text at 0x11c793610>,
 <matplotlib.text.Text at 0x11c773cd0>,
 <matplotlib.text.Text at 0x11e43b650>]

In [43]:
ax = fast[fast.year_published == 2015].drop(['total','days_to_90p','Published','month_published','year_published',
          "month_year_published"],axis=1).mean(axis=0).plot()
ax.set(xlabel='Days Since Publication',ylabel ='Average Daily Page Views',title = 'Average Daily Traffic for Content with short halflife 2015 ')


Out[43]:
[<matplotlib.text.Text at 0x124c96e10>,
 <matplotlib.text.Text at 0x12522db50>,
 <matplotlib.text.Text at 0x11e594790>]

In [44]:
df['fast_or_slow'] = ['fast' if x < 50 else 'slow' for x in df.days_to_90p]

In [ ]:


In [45]:
plt.figure(figsize=(20,10))
ax = sns.pointplot(x=pd.to_datetime(df.month_year_published),y='days_to_90p',hue='fast_or_slow',data=df)
ax.set_xticklabels(ax.get_xticklabels(),rotation=30)
plt.show()



In [63]:
df_ninety = df.iloc[:,:92]

In [64]:
df_ninety.head(1)


Out[64]:
index 0 1 2 3 4 5 6 7 8 ... 81 82 83 84 85 86 87 88 89 90
0 10-affordable-chardonnays-that-arent-oak-bombs 457.0 720.0 241.0 79.0 38.0 30.0 41.0 34.0 87.0 ... 1.0 2.0 6.0 4.0 4.0 1.0 2.0 1.0 1.0 1.0

1 rows × 92 columns


In [69]:
df_ninety['days_to_90p'] = [(df_ninety.iloc[x].expanding().sum() > df_ninety.iloc[x].sum()*.90).argmax()\
                     for x in range(len(df_ninety))]


---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-69-d5faa0a02729> in <module>()
----> 1 df_ninety['days_to_90p'] = [(df_ninety.iloc[x].expanding().sum() > df_ninety.iloc[x].sum()*.90).argmax()                     for x in range(len(df_ninety))]

/Users/Mike/anaconda/lib/python2.7/site-packages/pandas/core/generic.pyc in stat_func(self, axis, skipna, level, numeric_only, **kwargs)
   5308                                       skipna=skipna)
   5309         return self._reduce(f, name, axis=axis, skipna=skipna,
-> 5310                             numeric_only=numeric_only)
   5311 
   5312     return set_function_name(stat_func, name, cls)

/Users/Mike/anaconda/lib/python2.7/site-packages/pandas/core/series.pyc in _reduce(self, op, name, axis, skipna, numeric_only, filter_type, **kwds)
   2243                 raise NotImplementedError('Series.{0} does not implement '
   2244                                           'numeric_only.'.format(name))
-> 2245             return op(delegate, skipna=skipna, **kwds)
   2246 
   2247         return delegate._reduce(op=op, name=name, axis=axis, skipna=skipna,

/Users/Mike/anaconda/lib/python2.7/site-packages/pandas/core/nanops.pyc in _f(*args, **kwargs)
     42                                     f.__name__.replace('nan', '')))
     43             try:
---> 44                 return f(*args, **kwargs)
     45             except ValueError as e:
     46                 # we want to transform an object array

/Users/Mike/anaconda/lib/python2.7/site-packages/pandas/core/nanops.pyc in f(values, axis, skipna, **kwds)
    101             except Exception:
    102                 try:
--> 103                     result = alt(values, axis=axis, skipna=skipna, **kwds)
    104                 except ValueError as e:
    105                     # we want to transform an object array

/Users/Mike/anaconda/lib/python2.7/site-packages/pandas/core/nanops.pyc in nansum(values, axis, skipna)
    272     elif is_timedelta64_dtype(dtype):
    273         dtype_sum = np.float64
--> 274     the_sum = values.sum(axis, dtype=dtype_sum)
    275     the_sum = _maybe_null_out(the_sum, axis, mask)
    276 

/Users/Mike/anaconda/lib/python2.7/site-packages/numpy/core/_methods.pyc in _sum(a, axis, dtype, out, keepdims)
     30 
     31 def _sum(a, axis=None, dtype=None, out=None, keepdims=False):
---> 32     return umr_sum(a, axis, dtype, out, keepdims)
     33 
     34 def _prod(a, axis=None, dtype=None, out=None, keepdims=False):

TypeError: ufunc 'add' did not contain a loop with signature matching types dtype('S46') dtype('S46') dtype('S46')

In [43]:
df_ninety['total'] = df_ninety.iloc[:,:92].sum(axis=1)


Out[43]:
(1336, 1175)

In [68]:
df_ninety.dtypes


Out[68]:
index     object
0        float64
1        float64
2        float64
3        float64
4        float64
5        float64
6        float64
7        float64
8        float64
9        float64
10       float64
11       float64
12       float64
13       float64
14       float64
15       float64
16       float64
17       float64
18       float64
19       float64
20       float64
21       float64
22       float64
23       float64
24       float64
25       float64
26       float64
27       float64
28       float64
          ...   
61       float64
62       float64
63       float64
64       float64
65       float64
66       float64
67       float64
68       float64
69       float64
70       float64
71       float64
72       float64
73       float64
74       float64
75       float64
76       float64
77       float64
78       float64
79       float64
80       float64
81       float64
82       float64
83       float64
84       float64
85       float64
86       float64
87       float64
88       float64
89       float64
90       float64
dtype: object

In [ ]: